﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace IA2NeuralNetwork.CharMap
{
    public class CharRaw
    {
        public string Data;

        public CharRaw(string data)
        {
            this.Data = data.ToUpper();
        }

        public bool Equals(CharRaw obj)
        {
            return this.Data.Equals(obj.Data);
        }

        #region Cast

        private int GetMapPosition()
        {
            NeuralNetworkCharMap map = NeuralNetworkCharMap.Instance;
            List<CharRaw> list = map.RawMap;
            for (int i = 0; i < list.Count(); i++)
            {
                if (this.Equals(list[i]))
                {
                    return i;
                }
            }

            return -1;
        }

        public CharByte ToCharByte()
        {
            NeuralNetworkCharMap map = NeuralNetworkCharMap.Instance;
            int i = this.GetMapPosition();
            return map.BytesMap[i];
        }

        public static implicit operator CharByte(CharRaw obj)
        {
            return obj.ToCharByte();
        }

        public CharLabel ToCharLabel()
        {
            NeuralNetworkCharMap map = NeuralNetworkCharMap.Instance;
            int i = this.GetMapPosition();
            return map.LabelMap[i];
        }

        public static implicit operator CharLabel(CharRaw obj)
        {
            return obj.ToCharLabel();
        }

        #endregion

        public override string ToString()
        {
            return this.Data;
        }
    }
}
